<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>Switch Tests</title>
<script type="text/javascript" src="../../deviceTheme.js"></script>
<script type="text/javascript" src="../../../../dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: true"></script>
<script language="JavaScript" type="text/javascript">
	require([
		"dojo/dom-construct", // dojo.place
		"dojo/ready", // dojo.ready
		"dijit/registry",  // dijit.byId
		"doh/runner",	//doh functions
		"dojox/mobile/Switch",
		"dojox/mobile",				// This is a mobile app.
		"dojox/mobile/View",		// This mobile app uses mobile view
		"dojox/mobile/compat",		// This mobile app supports running on desktop browsers
		"dojox/mobile/parser"		// This mobile app uses declarative programming with fast mobile parser
	], function(domConst, ready, registry, runner, Switch){
		function _createSwitchDeclaratively(id) {
			return registry.byId(id);
		};
		
		function _createSwitchProgrammatically(placeHolderId){
			var widget = new Switch();
			runner.assertNotEqual(null, widget);
			domConst.place(widget.domNode, placeHolderId, "replace");
			widget.startup();
			return widget;
		};
		
		function _createSwitchProgrammaticallyWithSourceNodeReference(id){
			var widget = new Switch({}, id);
			widget.startup();
			return widget;
		};

		function _assertCorrectSwitch(switchButton){
			runner.assertNotEqual(null, switchButton);
			runner.assertEqual("on", switchButton.value);
			switchButton.set("value", "off");
			runner.assertEqual("off", switchButton.value);		
		};
		
		function _showView2(){
			var view1 = registry.byId("view1");
			view1.performTransition("view2", 1, "none");
		};

		ready(function(){
			runner.register("dojox.mobile.test.doh.SwitchTests", [
				function testInView1(){
					var switch1 = _createSwitchDeclaratively("view1-switch1");
					var switch2 = _createSwitchProgrammatically("view1-switch2");
					var switch3 = _createSwitchProgrammaticallyWithSourceNodeReference("view1-switch3");
			
					_assertCorrectSwitch(switch1);
					_assertCorrectSwitch(switch2);
					_assertCorrectSwitch(switch3);
				},
				function testInView2(){
					var switch1 = _createSwitchDeclaratively("view2-switch1");
					var switch2 = _createSwitchProgrammatically("view2-switch2");
					var switch3 = _createSwitchProgrammaticallyWithSourceNodeReference("view2-switch3");
					
					_showView2();
					
					_assertCorrectSwitch(switch1);
					_assertCorrectSwitch(switch2);
					_assertCorrectSwitch(switch3);
				}
			]);
			runner.run();
		});
	})
</script>
</head>
<body>
	<div id="view1" data-dojo-type="dojox.mobile.View" selected="true">
		<h1>View 1</h1>
		<div id="view1-switch1" data-dojo-type="dojox.mobile.Switch"></div>
		<div id="view1-switch2"></div>
		<div id="view1-switch3"></div>
	</div>	
	<div id="view2" data-dojo-type="dojox.mobile.View">
		<h1>View 2</h1>
		<div id="view2-switch1" data-dojo-type="dojox.mobile.Switch"></div>
		<div id="view2-switch2"></div>
		<div id="view2-switch3"></div>
	</div>
</body>
</html>
